home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / LINUX / MATH_EMU.ZIP / MATH_EMU / FPU_TRIG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1979-12-31  |  5.5 KB  |  226 lines

  1. /*        $NetBSD$  */
  2.  
  3. /*
  4.  * Copyright (c) 1995  Ken Nakata
  5.  *        All rights reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Redistributions in binary form must reproduce the above copyright
  13.  *    notice, this list of conditions and the following disclaimer in the
  14.  *    documentation and/or other materials provided with the distribution.
  15.  * 3. Neither the name of the author nor the names of its contributors
  16.  *    may be used to endorse or promote products derived from this software
  17.  *    without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  *
  31.  *        @(#)fpu_trig.c      10/24/95
  32.  */
  33. #include "types.h"
  34. #include "fpu_emul.h"
  35.  
  36.  
  37. void fpu_sin_or_cos(struct fpemu *, int);
  38.  
  39. extern struct xtable {
  40.     int    sp_exp;
  41.     u_int    sp_m0,sp_m1,sp_single;
  42. } pitbl[];
  43.  
  44.  
  45.  
  46. static u_int tanQ4[] = { 0x3EA0B759,0xF50F8688 };
  47. static u_int tanP3[] = { 0xBEF2BAA5,0xA8924F04 };
  48. static u_int tanQ3[] = { 0xBF346F59,0xB39BA65F,0x00000000 };
  49. static u_int tanP2[] = { 0x3FF60000,0xE073D3FC,0x199C4A00 };
  50. static u_int tanQ2[] = { 0x3FF90000,0xD23CD684,0x15D95FA1 };
  51. static u_int tanP1[] = { 0xBFFC0000,0x8895A6C5,0xFB423BCA };
  52. static u_int tanQ1[] = { 0xBFFD0000,0xEEF57E0D,0xA84BC8CE };
  53.  
  54. u_int TWOBYPI[]= { 0x3FE45F30, 0x6DC9C883 };
  55. u_int TWOPI[]=     { 0x40010000, 0xC90FDAA2,0x2168C235 };
  56.  
  57.  
  58.  
  59. struct fpn *
  60. fpu_acos(fe)
  61.      struct fpemu *fe;
  62. {
  63.   /* stub */
  64.   return &fe->fe_f2;
  65. }
  66.  
  67. struct fpn *
  68. fpu_asin(fe)
  69.      struct fpemu *fe;
  70. {
  71.   /* stub */
  72.   return &fe->fe_f2;
  73. }
  74.  
  75. struct fpn *
  76. fpu_atan(fe)
  77.      struct fpemu *fe;
  78. {
  79.   /* stub */
  80.   return &fe->fe_f2;
  81. }
  82.  
  83.  
  84. struct fpn *
  85. fpu_tan(fe)
  86.      struct fpemu *fe;
  87. {
  88.   
  89.   
  90.     static struct fpn X,S,U,V;
  91.     static struct fpn *d;
  92.     int     N;
  93.     
  94.         
  95.  
  96.     CPYFPN(&X, &fe->fe_f2);
  97.  
  98.     /* reduce argument if necessary */
  99.     if(X.fp_exp > 5 || (X.fp_exp == 5 &&  X.fp_mant[0] >= (0xbc7e00 >> (31 - FP_LG))) ) {
  100.          CPYFPN(&fe->fe_f1,&fe->fe_f2);
  101.          fpu_explode(fe, &fe->fe_f2,FTYPE_EXT, TWOPI);
  102.          
  103.          d=fpu_rem(fe);
  104.          CPYFPN(&X ,d);
  105.          
  106.     };
  107.         if(X.fp_exp <= -40) {
  108.                  
  109.                      return &fe->fe_f2;             
  110.         };
  111.         
  112.         
  113.  
  114.     
  115.        
  116.         fpu_explode(fe, &fe->fe_f1, FTYPE_DBL, TWOBYPI);
  117.     CPYFPN(&fe->fe_f2,&X)
  118.         d = fpu_mul(fe);
  119.         fpu_implode(fe, d, FTYPE_LNG, &N);
  120.         
  121.       
  122.  
  123.     CPYFPN(&fe->fe_f1, &X);
  124.            fpu_explode(fe, &fe->fe_f2, FTYPE_EXT, &(pitbl[32+N].sp_exp));
  125.          fe->fe_f2.fp_sign= ! fe->fe_f2.fp_sign; 
  126.            d=fpu_add(fe);
  127.             
  128.         CPYFPN(&fe->fe_f1, d);
  129.         fpu_explode(fe, &fe->fe_f2, FTYPE_SNG, &(pitbl[32+N].sp_single));
  130.            fe->fe_f2.fp_sign= ! fe->fe_f2.fp_sign;           
  131.            d=fpu_add(fe);
  132.  
  133.           
  134.            
  135.            CPYFPN(&X, d);
  136.         CPYFPN(&fe->fe_f1, d);
  137.      CPYFPN(&fe->fe_f2, d);
  138.      d=fpu_mul(fe);
  139.      CPYFPN(&S, d);           
  140.     
  141.     
  142.     /* calc U */
  143.     
  144.     CPYFPN(&fe->fe_f1, &S);
  145.     fpu_explode(fe, &fe->fe_f2, FTYPE_DBL, tanP3);
  146.     d=fpu_mul(fe);
  147.     CPYFPN(&fe->fe_f2, d);
  148.            fpu_explode(fe, &fe->fe_f1, FTYPE_EXT, tanP2);
  149.            d=fpu_add(fe);
  150.            CPYFPN(&fe->fe_f2, d);
  151.        
  152.            CPYFPN(&fe->fe_f1, &S);
  153.     d=fpu_mul(fe);
  154.     CPYFPN(&fe->fe_f2,d);
  155.            fpu_explode(fe, &fe->fe_f1, FTYPE_EXT, tanP1);
  156.            d=fpu_add(fe);
  157.            CPYFPN(&fe->fe_f2, d);
  158.         
  159.          
  160.            CPYFPN(&fe->fe_f1, &S);
  161.     d=fpu_mul(fe);
  162.     CPYFPN(&fe->fe_f2,d);       
  163.       
  164.      
  165.            CPYFPN(&fe->fe_f1, &X);
  166.     d=fpu_mul(fe);
  167.     CPYFPN(&fe->fe_f2, d);
  168.            CPYFPN(&fe->fe_f1, &X);
  169.            d=fpu_add(fe);
  170.            CPYFPN(&U, d);
  171.  
  172.     /* calc V */
  173.     
  174.     
  175.     CPYFPN(&fe->fe_f1, &S);
  176.     fpu_explode(fe, &fe->fe_f2, FTYPE_DBL, tanQ4);
  177.     d=fpu_mul(fe);
  178.     CPYFPN(&fe->fe_f2, d);
  179.            fpu_explode(fe, &fe->fe_f1, FTYPE_EXT, tanQ3);
  180.            d=fpu_add(fe);
  181.            CPYFPN(&fe->fe_f2, d);
  182.        
  183.            CPYFPN(&fe->fe_f1, &S);
  184.     d=fpu_mul(fe);
  185.     CPYFPN(&fe->fe_f2,d);
  186.            fpu_explode(fe, &fe->fe_f1, FTYPE_EXT, tanQ2);
  187.            d=fpu_add(fe);
  188.            CPYFPN(&fe->fe_f2, d);
  189.            
  190.              
  191.            CPYFPN(&fe->fe_f1, &S);
  192.     d=fpu_mul(fe);
  193.     CPYFPN(&fe->fe_f2,d);
  194.            fpu_explode(fe, &fe->fe_f1, FTYPE_EXT, tanQ1);
  195.            d=fpu_add(fe);
  196.            CPYFPN(&fe->fe_f2, d);
  197.                    
  198.          
  199.            CPYFPN(&fe->fe_f1, &S);
  200.     d=fpu_mul(fe);
  201.     CPYFPN(&fe->fe_f2,d);       
  202.       
  203.      
  204.            fpu_const(&fe->fe_f1, 0x32);
  205.     d=fpu_add(fe);
  206.     CPYFPN(&V, d);
  207.         
  208.         if (N & 0xfffffffe == N) {
  209.              CPYFPN(&fe->fe_f1, &U);
  210.              CPYFPN(&fe->fe_f2, &V);
  211.              d=fpu_div(fe);
  212.         CPYFPN(&fe->fe_f2, d);
  213.         
  214.         } else {
  215.                 CPYFPN(&fe->fe_f1, &V);
  216.              CPYFPN(&fe->fe_f2, &U);
  217.              d=fpu_div(fe);
  218.         CPYFPN(&fe->fe_f2, d);
  219.         fe->fe_f2.fp_sign= ! fe->fe_f2.fp_sign;
  220.         
  221.         }
  222.        
  223.   return &fe->fe_f2;
  224. }
  225.  
  226.